alter table Category
add NotMergeable bit not null default(0)
go
ALTER PROCEDURE [dbo].[spCategory_Add]
(
	@CategoryName VARCHAR(250),
	@ParentId INT = NULL,
	@IsSingularSelection BIT = 0,
	@IsRoot BIT = 0,
	@SortOrder int = 0,
	@CategoryDescription varchar(200) = '',
	@NotMergeable bit = 0
)
AS
BEGIN
	SET NOCOUNT ON
	
	IF (@ParentId IS NOT NULL)
	BEGIN
		DECLARE @IsSingularSelectionParent BIT
		
		SELECT @IsSingularSelectionParent = IsSingularSelection
		FROM Category
		WHERE CategoryId = @ParentId
		
		IF (@IsSingularSelectionParent = 1)
			SET @IsSingularSelection = 1
	END	
	
	INSERT INTO Category
	(CategoryName, ParentId, IsSingularSelection, IsRoot, SortOrder, CategoryDescription, NotMergeable)
	VALUES (@CategoryName, @ParentId, @IsSingularSelection, @IsRoot, @SortOrder, @CategoryDescription, @NotMergeable)
END
go
ALTER PROCEDURE [dbo].[spCategory_Update]
(
	@CategoryId int,
	@CategoryName VARCHAR(250),
	@ParentId INT = NULL,
	@IsSingularSelection BIT = 0,
	@IsRoot BIT = 0,
	@SortOrder int = 0,
	@CategoryDescription varchar(200) = '',
	@NotMergeable bit = 0
)
AS
BEGIN
	SET NOCOUNT ON
	
	IF (@ParentId IS NOT NULL)
	BEGIN
		DECLARE @IsSingularSelectionParent BIT
		
		SELECT @IsSingularSelectionParent = IsSingularSelection
		FROM Category
		WHERE CategoryId = @ParentId
		
		IF (@IsSingularSelectionParent = 1)
			SET @IsSingularSelection = 1
	END	
	

	update Category
	set
		CategoryName = @CategoryName,
		ParentId = @ParentId,
		IsSingularSelection = @IsSingularSelection,
		IsRoot = @IsRoot,
		SortOrder = @SortOrder,
		CategoryDescription = @CategoryDescription,
		NotMergeable = @NotMergeable
	where CategoryId = @CategoryId
END
go